package com.jldx.oa.controller;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jldx.common.Result;
import com.jldx.oa.bean.GoodsCategory;

public class GoodsCategoryController extends BaseController{

	public void index(){
		render("/WEB-INF/views/goods_category.html");
	}
	
	public void query(){
		Integer pageNumber = getPage();
		String title = getPara("title");
		Integer limit = getLimit();
		Kv cond = Kv.by("name", title);
		SqlPara sqlPara = Db.getSqlPara("oa.goodsCategoryList",cond);//,cond);
		Page<GoodsCategory> page = GoodsCategory.dao.paginate(pageNumber, limit, sqlPara);
		Result result = Result.cast(page);
		renderJson(result);
	}
	
	public void edit(){
		Integer id = getParaToInt("id");
		if(id!=null){
			GoodsCategory goodsCategory = GoodsCategory.dao.findById(id);
			setAttr("goodsCategory", goodsCategory);
		}
		view("goods_category_edit.html");
	}
	
	public void save(){
		GoodsCategory goodsCategory = getModel(GoodsCategory.class,"");
		if(goodsCategory.getId()!=null){
			goodsCategory.update();
		}else{
			goodsCategory.save();
		}
		renderText("suc");
	}
	
	public void delete(){
		Integer id = getParaToInt("id");
		boolean result = false;
		if(id!=null){
			result = GoodsCategory.dao.deleteById(id);
		}
		if(result){
			renderText("suc");
		}else{
			render("fail");
		}
	}
}
